package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Button.ClickListener;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.GameDescription;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.game.kodomosuit.SuitKomodo;
import com.komodo.island.gdx.game.komodobalance.GameBalance;
import com.komodo.island.gdx.game.komodomove.KomodoMove;
import com.komodo.island.gdx.game.komodophoto.KomodoPhoto;
import com.komodo.island.gdx.game.sandcastle.SandCastle;
import com.komodo.island.gdx.game.underwater.KomodoUnderwater;
import com.komodo.island.gdx.screen.GameScreen;
import com.komodo.island.gdx.screen.Screen;

public class PauseDialog extends Dialog {

	private Button mainMenu;
	private Button play;
	private Button retry;
	private Button help;
	private Image bgImage;
	private Image pauseText;
	
	
//	public HelpScreen helpScreen;
	
	public Image siKomo;

	
	public PauseDialog(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture, komodoIsland);
		// TODO Auto-generated constructor stub
		ID = Input.DIALOG_PAUSE;

	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		// textureName = Constants.menuTexture;
		// initByName();
//		helpScreen = new HelpScreen(null, 1, 5000, screen);
//		helpScreen.init(screen.komodoIsland, komodoIsland.helpTexture);
		background = new Image("background", new TextureRegion(komodoIsland.menuTexture, 480, 0, 480, 320));
		
		bgImage = new Image("bg", new TextureRegion(texture, 0, 0, 351, 194));
		pauseText = new Image("pause", new TextureRegion(texture, 351+200,71+28*2+64, 97, 29));

		siKomo= new Image("komo", new TextureRegion(texture, 351+200+179, 0,
				100, 102));
		
		
		play = new Button("play", new TextureRegion(
				texture,  351+200,71+28*2, 64, 64),
				new TextureRegion(texture,  351+200,71+28*2,
						64, 64));

		play.width = 32;
		play.height = 32;
		
		mainMenu = new Button("main menu", new TextureRegion(texture,351+200+97,71+28*2+64, 32, 32), new TextureRegion(texture,351+200+97+32,71+28*2+64, 32,
				32));
		
		help = new Button("help", new TextureRegion(texture,351+200+97,71+28*2+64+32, 32, 32), new TextureRegion(texture,351+200+97+32,71+28*2+64+32, 32,
				32));
		
		retry = new Button("retry", new TextureRegion(texture,351+200,71+28*2+64+28, 32, 32), new TextureRegion(texture,351+200+32,71+28*2+64+28, 32,
				32));
		

	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub
		addActor(background);
		addActor(bgImage);
		addActor(pauseText);
		addActor(siKomo);
		addActor(mainMenu);
		addActor(play);
		addActor(retry);
		addActor(help);
	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub
		bgImage.x = 240 - 351 / 2;
		bgImage.y = 160 - 194 / 2;

		 siKomo.x =bgImage.x + 28;
		 siKomo.y = bgImage.y + 194 - siKomo.height - 14;

		pauseText.x = bgImage.x + 28 + bgImage.width / 3 - 10;
		pauseText.y = bgImage.y + 64 * 2 + 14;

		play.x = bgImage.x + 128+64 -16;
		play.y = bgImage.y + 96;
		
		retry.x = play.x + play.width + 32;
		retry.y = play.y ;
		
		help.x = play.x;
		help.y = play.y -32 - 15;

		mainMenu.x = help.x +help.width + 32;
		mainMenu.y = help.y;

	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub
		retry.clickListener = new ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.gameMenuSound.play(1);
//				System.out.println("Retry");
				((GameScreen) screen).retryGame();
			}
		};

		play.clickListener = new ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
//				System.out.println("Resume");
				if (Persistence.sound)
					komodoIsland.gameMenuSound.play(1);
				((GameScreen) screen).resumeGame();
			}
		};
		mainMenu.clickListener = new ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
//				System.out.println("EXIT");
				if (Persistence.sound)
					komodoIsland.gameMenuSound.play(1);
				((GameScreen) screen).exitScreen();
			}
		};

		help.clickListener = new ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
//				((GameScreen) screen).pauseGame();
				if (Persistence.sound)
					komodoIsland.gameMenuSound.play(1);
				int index = 0;
				if (screen instanceof SuitKomodo){
					index = GameDescription.SUIT;
				}else if (screen instanceof GameBalance){
					index = GameDescription.BALANCE;
				}else if (screen instanceof SandCastle){
					index = GameDescription.CASTLE;
//				} else if (screen instanceof ShoppingGame){
//					index = GameDescription.SHOPPING;
				} else if (screen instanceof KomodoPhoto){
					index = GameDescription.PHOTO;
				} else if (screen instanceof KomodoUnderwater){
					index = GameDescription.UNDERWATER;
				} else if (screen instanceof KomodoMove){
					index = GameDescription.MOVE;
				}  
				komodoIsland.helpScreen.nextScreen = screen;
				komodoIsland.helpScreen.setHelp(index);
				((GameScreen)screen).komodoIsland.goToScreen(komodoIsland.helpScreen);
			}
		};
		
		
	}
	

}
